<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePicturesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('pictures', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->nullable();
            $table->integer('size')->default(0);
            $table->integer('width')->default(0);
            $table->integer('height')->default(0);
            $table->string('path')->comment('路径');
            $table->string('url')->comment('图片链接');
            $table->string('file_name')->comment('图片原始名称');
            $table->string('md5')->comment('图片内容的md5值');
//            $table->integer('picturetable_id')->comment('外联id')->nullable();
//            $table->string('picturetable_type')->comment('外联所属模型的类名')->nullable();
            $table->timestamps();
            $table->timestamp('deleted_at')->nullable();

            $table->index('user_id');
            $table->index('md5');
        });
        Schema::create('picturegables', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('picture_id')->nullable();
            $table->integer('picturegable_id')->comment('外联id')->nullable();
            $table->string('picturegable_type')->comment('外联所属模型的类名')->nullable();

            $table->index('picture_id');
            $table->index('picturegable_id');
            $table->index('picturegable_type');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('pictures');
        Schema::dropIfExists('picturegables');
    }
}
